package com.hsource.doctorcenter.controller;

import com.hsource.common.utils.CommonCallBackResp;
import com.hsource.common.utils.resultUtils.controller.BaseController;
import com.hsource.doctorcenter.manager.AsyncManager;
import com.hsource.doctorcenter.manager.factory.AsyncFactory;
import com.hsource.doctorcenter.util.ServletUtils;
import com.hsource.doctorcenter.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author yangYang
 * @version 1.0
 * @date 2020/10/19 11:45
 * @describe
 */
@Slf4j
@Controller
@RequestMapping("/callback")
public class CallBackController extends BaseController {

    /**
     * 医生关回复回调
     * @param requestBodyString 请求body参数
     * @return
     */
    @PostMapping("/reply")
    @ResponseBody
    public CommonCallBackResp reply(@RequestBody String requestBodyString){
        log.info("======reply==========="+requestBodyString);
        if(StringUtils.isBlank(requestBodyString)){
            return callBackFailed();
        }
        AsyncManager.me().execute(AsyncFactory.callBackReplyDataTimerTask(requestBodyString));
        return callBackSuccess();
    }

    /**
     * 医生关闭回调
     * @param requestBodyString 请求body参数
     * @return
     */
    @PostMapping("/close")
    @ResponseBody
    public CommonCallBackResp close(@RequestBody String requestBodyString){
        log.info("=============close===="+requestBodyString);
        Map<String, Object> requestBodyAnalysis = ServletUtils.getRequestBodyAnalysis(requestBodyString);
        if(StringUtils.isNull(requestBodyAnalysis)){
            return callBackFailed();
        }
        AsyncManager.me().execute(AsyncFactory.callBackDataTimerTask(requestBodyAnalysis));
        return  callBackSuccess();
    }


}
